var empBoardNo = 0;
var workNo = 0;
var deptNo=0;
var teamNo=0;
var deptBoardNo=0;
var year;
var month;
var pageNum;
var workPageNum;
var deptBoardPageNum;
var upperWorkNo;
var docNo;
var fileNo;
var day;


$(document).ready(function() {
	$.history.init(historyStorage);
});

function setDocNo(docNo){
	this.docNo = docNo;
}
function getDocNo(){
	return docNo;
}
function setFileNo(fileNo){
	this.fileNo = fileNo;
}
function getFileNo(){
	return fileNo;
}

function getUpperWorkNo(){
	return upperWorkNo;
}
function setUpperWorkNo(upperWorkNo){
	this.upperWorkNo = upperWorkNo;
}

function getPageNum() {
	return pageNum;
}
function setPageNum(pageNum) {
	this.pageNum = pageNum;
}
function getWorkPageNum(){
	return workPageNum;
}
function setWorkPageNum(workPageNum){
	this.workPageNum = workPageNum;
}

function setEmpBoardNo(no) {
	this.empBoardNo = no;
}
function getEmpBoardNo() {
	return this.empBoardNo;
}

function setWorkNo(no) {
	this.workNo = no;
}
function getWorkNo() {
	return this.workNo;
}

function setDeptBoardNo(boardNo){
	this.deptBoardNo = boardNo;
}
function getDeptBoardNo(){
	return deptBoardNo;
}
function setDeptBoardPageNum(deptBoardPageNum){
	this.deptBoardPageNum=deptBoardPageNum;
}
function getDeptBoardPageNum(){
	return this.deptBoardPageNum;
}
function setDeptNo(deptNo){
	this.deptNo = deptNo;
}
function getDeptNo(){
	return this.deptNo;
}
function setTeamNo(teamNo){
	this.teamNo = teamNo;
}
function getTeamNo(){
	return this.teamNo;
}

function setEmpNo(empNo){
	this.empNo = empNo;
}
function getEmpNo(){
	return this.empNo;
}

function setYear(year){
	this.year = year;
}
function setMonth(month){
	this.month = month;
}
function setDay(day){
	this.day = day;
}
function getYear(){
	return this.year;
}
function getMonth(){
	return this.month;
}
function getDay(){
	return this.day;
}

function historyStorage(hash) {
	if (hash) {
		//My page history
		switch (hash) {
		case 'scheduleWeek':
			$('.board_contents').load('employee/schedule/week', { year:getYear(), month:getMonth(), day:getDay()});
			break;
		case 'scheduleList':
			$('.board_contents').load('employee/schedule/list', {empNo:getEmpNo()});
			break;
		case 'scheduleAdd':
			$('.board_contents').load('employee/schedule/add', {empNo:getEmpNo()});
			break;
		case 'documentPick':
			$('.project_contents').load('project/document/' + getDocNo());
			break;
		case 'updateUpperWork':
			$('.project_contents').load('project/work/updateUpperWork', {workNo:getWorkNo(), upperWorkNo:getUpperWorkNo()});
			break;
		case 'updateDocument':
			$('.project_contents').load('project/work/updateDocument', {workNo:getWorkNo(), docNo:getDocNo()});
			break;
		case 'updateFile':
			$('.project_contents').load('project/work/updateFile', {workNo:getWorkNo(), fileNo:getFileNo()});
			break;
		case 'createChildWork':
			$('.project_contents').load('project/createWork/childWork', {workNo:getWorkNo()});
			break;
		case 'employeeSchedule':
			$('.board_contents').load('employee/schedule');
			break;
		case 'projectPickWork':
			$('.page_wrap').load('project/pickWork/' + getWorkNo());
			break;
		case 'boardWrite':
			$('.board_contents').load('employee/write');
			break;
		case 'boardModify':
			$('.board_contents').load('employee/modify', {
				empBoardNo : getEmpBoardNo(),
			});
			break;
		case 'boardList':
			$('.board_contents').load('employee/list');
			break;
		case 'boardListPage':
			$('.board_contents').load('employee/list', {
				num : getPageNum()
			});
			break;
		case 'boardContents':
			$('.board_contents').load('employee/contents/' + getEmpBoardNo(), {
				num : getPageNum()
			});
			break;
			
		// project history	
		case 'projectMainAction':
			$('.page_wrap').load('project/projectMainAction');
			break;
		case 'projectWorkAction':
			$('.page_wrap').load('project/projectWorkAction');
			break;
		case 'projectWorkList':
			$('.project_contents').load('project/workList');
			break;
		case 'projectWorkModify':
			$('.project_contents').load('project/work/' + getWorkNo() + "/modify");
			break;
		case 'projectSummary':
			$('.project_contents').load('project/summary');
			break;
		case 'projectJobHistory':
			$('.project_contents').load('project/history');
			break;
		case 'projectCreateWork':
			$('.project_contents').load('project/createWork');
			break;
		case 'projectCalendar':
			$('.project_contents').load('project/calendar');
			break;
		case 'projectFile':
			$('.project_contents').load('project/file');
			break;
		case 'projectDocument':
			$('.project_contents').load('project/document');
			break;
		case 'projectGantt':
			$('.project_contents').load('project/gantt');
			break;
		case 'projectWorkPage':
			$('.project_contents').load("project/work/" + getWorkNo());
			break;
		case 'projectWorkSearchPage':
			break;
			
		case 'projectPrintOut':
			$('.project_contents').load("project/printOut");
			break;
		//Department Board 
		case 'deptMainAction': 
			$(".page_wrap").load('dept/deptteamList');
			break;
		case 'deptBoardList':
			$('.dept_board').load('dept/deptBoardList');
			break;
		case 'deptBoardListPage':
			$('.dept_board').load('dept/deptBoardList', {
				num : getDeptBoardPageNum()
			});
			break;
		case 'deptBoardContents':
			$('.dept_board').load("dept/contents/"+getDeptBoardNo(), 
					{num : getDeptBoardPageNum()
			});
			break;
		case 'deptBoardModify':
			$('.dept_board').load('dept/modify', 
					{deptBoardNo : getDeptBoardNo()
			});
			break;
		case 'deptBoardWrite':
			$('.dept_board').load('dept/write');
			break;
			
		//dept memberBoard
		case 'memberboardWrite':
			$('.board_contents').load('teamMember/write',{empNo:getEmpNo()});
			break;
		case 'memberboardModify':
			$('.board_contents').load('teamMember/modify', {
				empBoardNo : getEmpBoardNo(),
				empNo : getEmpNo()
			});
			break;
		case 'memberboardList':
			$('.board_contents').load('teamMember/list', {empNo:getEmpNo()});
			break;
		case 'memberBoardContents':
			$('.board_contents').load('teamMember/contents/' + getEmpBoardNo(), {
				num : getPageNum(), empNo : getEmpNo()
			});
		
		case 'teamMemberSchedule':
			$('.board_contents').load('teamMember/schedule', {empNo:getEmpNo()});
			break;
			
		default:
			var valid = /^boardListWithPageNum[0-9]$/;
			if (hash.match(valid)) { // boardListWithPageNum
				$('.board_contents').load('employee/list', {
					num : getPageNum()
				});
			}
			
			var valid2 = /^workListWithPageNum[0-9]$/;
			var workType = $("#search_type option:selected").val();
			var workState = $("#search_state option:selected").val();
			var workPriority = $("#search_priority option:selected").val();
			var writer = $("#search_writer option:selected").val();
			
			
			if(hash.match(valid2)){
				if(workType != '' || workState != '' || workPriority != '' || writer != ''){
					$('.project_contents').load('project/workList/search', {
						num : getWorkPageNum(), workType:workType, workState:workState, workPriority:workPriority, writer:writer
					});
				}else{
					$('.project_contents').load('project/workList', {
						num : getWorkPageNum()
					});
				}
			}
			
			var valid3 = /^projectWorkPage[0-9]+$/;
			if(hash.match(valid3)){
				$('.project_contents').load("project/work/" + getWorkNo());
			}
			
			var valid4 = /^deptBoardListPageNum[0-9]$/;
			if(hash.match(valid4)){
				$('.dept_board').load('dept/deptBoardList',{
					num: getDeptBoardPageNum()
				});
			}
			
			var valid5=/^deptTeamPage[0-9]+$/;
			if(hash.match(valid5)){
				$(".dept_board").load('dept/deptteamMemberlist/'+getTeamNo(),{
					deptNo:getDeptNo()
				});
			}
			var valid6 = /^memberboardListWithPageNum[0-9]$/;
			if (hash.match(valid6)) { // memberboardListWithPageNum
				$('.board_contents').load('teamMember/list', {
					num : getPageNum(),
					empNo : getEmpNo()
				});
			}
			
			var valid7 = /^teamMemberInfo[0-9]+$/;
			if(hash.match(valid7)){
				$(".team_page_wrap").load('teamMember/teamMemberInfo',{empNo : getEmpNo()});
			}
			
			break;
		}

	} else {

	}
}

function get_scheduleWeek(year, month, day, upAndDown){
	$('.board_contents').load('employee/schedule/week/change', {year:year, month:month,day:day, upAndDown:upAndDown});
	
}

function schedule_week( year, month, day){
	setYear(year);
	setMonth(month);
	setDay(day);
	$.history.load("scheduleWeek");
	
	
}


function schedule_add_action(empNo){
	setEmpNo(empNo);
	
	var option = $('select#select_every option:selected').val();
	if(option == "day"){
		var scTitle = $('input#title').val();
		var scContents = $('textarea#contents').val();
		var scStartDate = $('input#startDate').val();
		var scEndDate = $('input#endDate').val();
		var startTime = $('select#startTime option:selected').val();
		var endTime = $('select#endTime option:selected').val();
		
		var hasErrors = false;
		var error = "";
		
		if(scTitle == ""){
			error = error + "title이 비었습니다.\n";
			hasErrors = true;
		}
		var validDate = /^20[0-1][0-9]-[0-1][0-9]-[0-3][0-9]$/; // 정규식
		
		if (scStartDate != "") {
			if (!scStartDate.match(validDate)) {
				error = error + "시작 Date 형식이 맞지 않습니다.\n";
				hasErrors = true;
			}
		}
		if (scEndDate != "") {
			if (!scEndDate.match(validDate)) {
				error = error + "마감 Date 형식이 맞지 않습니다.\n";
				hasErrors = true;
			}
		}
		
		if(endTime < startTime){
			error = error + "마감시간이 시작시간보다 전이여야 합니다";
			hasErrors = true;
		}
		
		if(hasErrors){
			alert(error);
		}else{
			$.ajax({
				url : "employee/schedule/add/action",
				// type: "POST",
				data : ({
					empNo:empNo,
					scheduleTitle:scTitle,
					scheduleContents:scContents,
					scheduleStartDateString:scStartDate,
					scheduleEndDateString:scEndDate,
					startTime:startTime,
					endTime:endTime
				}),
				cache : false,
				contentType : "text/plain; charset=UTF-8",
				success : function(data) {
					alert('일정이 추가되었습니다.');
					$.history.load("scheduleList");
				}
			});
		}
	}else if(option == "everyWeek"){
		var option2 = $("input[name='gigan']:checked").val();
		
		var scTitle = $('input#title').val();
		var scContents = $('textarea#contents').val();
		var scStartDate = $('input#startDate').val();
		var scEndDate = $('input#endDate').val();
		var everyWeekDay = $('select#dayOfWeek option:selected').val();
		var startTime = $('select#startTime option:selected').val();
		var endTime = $('select#endTime option:selected').val();
		
		var hasErrors = false;
		var error = "";
		
		if(scTitle == ""){
			error = error + "title이 비었습니다.\n";
			hasErrors = true;
		}
		
		
		
		if(option2 == 'pick'){
			var validDate = /^20[0-1][0-9]-[0-1][0-9]-[0-3][0-9]$/; // 정규식
			
			if (scStartDate != "") {
				if (!scStartDate.match(validDate)) {
					error = error + "시작 Date 형식이 맞지 않습니다.\n";
					hasErrors = true;
				}
			}
			if (scEndDate != "") {
				if (!scEndDate.match(validDate)) {
					error = error + "마감 Date 형식이 맞지 않습니다.\n";
					hasErrors = true;
				}
			}
		}
		
		if(endTime < startTime){
			error = error + "마감시간이 시작시간보다 전이여야 합니다";
			hasErrors = true;
		}
		
		if(hasErrors){
			alert(error);
		}else if(option2 == "continue"){  //계속
			$.ajax({
				url : "employee/schedule/add/action/weekly",
				// type: "POST",
				data : ({
					empNo:empNo,
					scheduleTitle:scTitle,
					scheduleContents:scContents,
					everyWeekDay:everyWeekDay,
					startTime:startTime,
					endTime:endTime
				}),
				cache : false,
				contentType : "text/plain; charset=UTF-8",
				success : function(data) {
					alert('일정이 추가되었습니다.');
					$.history.load("scheduleList");
				}
			});
		}else if(option2 == "pick"){   //기간 선택
			$.ajax({
				url : "employee/schedule/add/action/weekly",
				// type: "POST",
				data : ({
					empNo:empNo,
					scheduleTitle:scTitle,
					scheduleContents:scContents,
					scheduleStartDateString:scStartDate,
					scheduleEndDateString:scEndDate,
					everyWeekDay:everyWeekDay,
					startTime:startTime,
					endTime:endTime
				}),
				cache : false,
				contentType : "text/plain; charset=UTF-8",
				success : function(data) {
					alert('일정이 추가되었습니다.');
					$.history.load("scheduleList");
				}
			});
		}
	}else if(option == "everyMonth"){
		var scTitle = $('input#title').val();
		var scContents = $('textarea#contents').val();
		var monthlyDay = $('input#pickDate').val();
		var pushWeekend = $('input#pushWeekend').attr('checked');
		var bool = false;
		var startTime = $('select#startTime option:selected').val();
		var endTime = $('select#endTime option:selected').val();
		
		if(pushWeekend == "checked"){
			bool = true;
		}
		
		var hasErrors = false;
		var error = "";
		
		if(scTitle == ""){
			error = error + "title이 비었습니다.\n";
			hasErrors = true;
		}
		
		if(endTime < startTime){
			error = error + "마감시간이 시작시간보다 전이여야 합니다";
			hasErrors = true;
		}
		
		if(hasErrors){
			alert(error);
		}else{
			$.ajax({
				url : "employee/schedule/add/action/monthly",
				// type: "POST",
				data : ({
					empNo:empNo,
					scheduleTitle:scTitle,
					scheduleContents:scContents,
					monthlyDay:monthlyDay,
					pushWeekend:bool,
					startTime:startTime,
					endTime:endTime
				}),
				cache : false,
				contentType : "text/plain; charset=UTF-8",
				success : function(data) {
					alert('일정이 추가되었습니다.');
					$.history.load("scheduleList");
				}
			});
		}
	}
	
}

function schedule_delete(scheduleNo){
	if (confirm('정말 삭제하시겠습니까?')) {

		$.ajax({
			url : "employee/schedule/delete",
			// type: "POST",
			data : ({scheduleNo:scheduleNo}),
			cache : false,
			contentType : "text/plain; charset=UTF-8",
			success : function(data) {
				alert('삭제되었습니다');
				$.history.load('employeeSchedule');
			}
		});
	}
}

function schedule_list(empNo){
	setEmpNo(empNo);
	$.history.load("scheduleList");
}
function schedule_add(empNo){
	setEmpNo(empNo);
	$.history.load("scheduleAdd");
}


function project_work_delete(workNo){
	if (confirm('정말 삭제하시겠습니까?')) {

		$.ajax({
			url : "project/work/delete",
			// type: "POST",
			data : ({workNo:workNo}),
			cache : false,
			contentType : "text/plain; charset=UTF-8",
			success : function(data) {
				alert('삭제되었습니다');
				$.history.load('projectWorkList');
			}
		});
	}	
}

function document_delete(docNo){
	if (confirm('정말 삭제하시겠습니까?')) {

		$.ajax({
			url : "project/document/delete",
			// type: "POST",
			data : ({docNo:docNo}),
			cache : false,
			contentType : "text/plain; charset=UTF-8",
			success : function(data) {
				alert('삭제되었습니다');
				$.history.load("projectDocument");
			}
		});
	}
}
function document_pick(docNo){
	setDocNo(docNo);
	$.history.load("documentPick");
}

function updateDocumentInWorkPage(workNo){
	var docNo = $('select#form_document option:selected').val();
	setDocNo(docNo);
	$.history.load("updateDocument");
}
function updateFileInWorkPage(workNo){
	var fileNo = $('select#form_file option:selected').val();
	setFileNo(fileNo);
	$.history.load("updateFile");
}

function updateUpperWorkInWorkPage(workNo){
	var upperWorkNo = $('select#form_upperWork option:selected	').val();
	setWorkNo(workNo);
	setUpperWorkNo(upperWorkNo);
	$.history.load("updateUpperWork");
}

function createChildWork(workNo){
	setWorkNo(workNo);
	$.history.load("createChildWork");
}

function pick_upperWork(workNo){
	setWorkNo(workNo);
	$.history.load("projectWorkPage" + workNo);
}
function pick_downerWork(workNo){
	setWorkNo(workNo);
	$.history.load("projectWorkPage" + workNo);
}
function workList_searchWork_type(workType){
	$.history.load("projectWorkSearchPage"); //고치지마
	$('.project_contents').load('project/workList/search', {workType:workType});
}

function workList_searchWork_state(workState){
	$.history.load("projectWorkSearchPage"); //고치지마
	$('.project_contents').load('project/workList/search', {workState:workState});
}

function workList_search(){
	var workType = $("#search_type option:selected").val();
	var workState = $("#search_state option:selected").val();
	var workPriority = $("#search_priority option:selected").val();
	var writer = $("#search_writer option:selected").val();
	
	$.history.load("projectWorkSearchPage"); //고치지마
	$('.project_contents').load('project/workList/search', {workType:workType, workState:workState, workPriority:workPriority, writer:writer});
	
}

function project_modifywork_action(relationNo, relationNo2){
	var workType = $("#form_workType").val();
	var workState = $("#form_workState").val();
	var workTitle = $("#form_workTitle").val();
	var workExplanation = $("#workExplanation").val();
	workExplanation = workExplanation.replace(/\n/g,"<br>");
	var workPriority = $("#form_workPriority").val();
	var id = $("#form_id").val();
	var startDate = $("#form_startDate").val();
	var deadDate = $("#form_deadDate").val();
	var file = $("#form_file").val();
	var coWorkers = $("#form_coWorkers").val();
	var workProgress = $('#form_workProgress').val();
	var upperWorkNo = $("#form_upperWork").val();
	var docNo = $('#form_document').val();
	var fileNo = $('#form_file').val();
	
	
	
	var hasError = false;

	$("#has_errors").text("");

	if (workTitle == "") {
		$("#has_errors").append("Title이 비어있습니다");
		hasError = true;
	}
	if (id == "") {
		$("#has_errors").append("<br>담당자가 비어있습니다");
		hasError = true;
	}

	var validDate = /^20[0-1][0-9]-[0-1][0-9]-[0-3][0-9]$/; // 정규식
	if (startDate != "") {
		if (!startDate.match(validDate)) {
			$("#has_errors").append("<br>Date 형식이 맞지않습니다");
			hasErrors = true;
		}
	}
	if (deadDate != "") {
		if (!deadDate.match(validDate)) {
			$("#has_errors").append("<br>Date 형식이 맞지않습니다");
			hasErrors = true;
		}
	}
	
	var validNumber = /^[0-9]+$/;
	
	
	if(upperWorkNo != ""){
		if(!upperWorkNo.match(validNumber)){
			$("#has_errors").append("<br>상위일감 형식이 맞지않습니다.");
			hasErrors = true;
		}
	}else{
		upperWorkNo = 0;
	}
	
	if(docNo != ""){
		if(!docNo.match(validNumber)){
			$("#has_errors").append("<br>문서번호 형식이 맞지않습니다.");
			hasErrors = true;
		}
	}else{
		docNo = 0;
	}
	if(fileNo != ""){
		if(!fileNo.match(validNumber)){
			$("#has_errors").append("<br>파일번호 형식이 맞지않습니다.");
			hasErrors = true;
		}
	}else{
		fileNo = 0;
	}
	if (hasError == false) {

		$.ajax({
			url : "project/modifyWork/action",
			// type : "POST",
			data : ({
				workNo:getWorkNo(),
				workType : workType,
				workState : workState,
				workTitle : workTitle,
				workPriority : workPriority,
				workExplanation : workExplanation,
				id : id,
				startDate : startDate,
				file : file,
				coWorkers:coWorkers,
				workProgress:workProgress,
				deadDate:deadDate,
				upperWorkNo:upperWorkNo,
				relationNo:relationNo,
				relationNo2:relationNo2,
				docNo:docNo,
				fileNo:fileNo
			}),
			cache : false,
			contentType : "text/plain; charset=UTF-8",
			success : function(data) {
				if (data == "fail_id") {
					alert("id가 잘못입력되었습니다");
				} else if (data == "fail_id_project") {
					alert("이 project에 속한 id가 아닙니다");
				} else if (data == "fail_project") {
					alert("project 번호가 잘못되었습니다");
				} else if (data == "fail_title_blank") {
					alert("title이 비어있습니다");
				} else if (data == "success") {
					$("#complete").text("업무가 수정되었습니다");
				} else {
					alert("알수 없는 오류가 발생했습니다");
				}
			}
		});

	}

}

function project_creatework_action() {

	var workType = $("#form_workType").val();
	var workState = $("#form_workState").val();
	var workTitle = $("#form_workTitle").val();
	var workExplanation = $("#workExplanation").val();
	workExplanation = workExplanation.replace(/\n/g,"<br>");
	var workPriority = $("#form_workPriority").val();
	var id = $("#form_id").val();
	var startDate = $("#form_startDate").val();
	var file = $("#form_file").val();
	var coWorkers = $("#form_coWorkers").val();
	var workProgress = $('#form_workProgress').val();
	var deadDate = $("#form_deadDate").val();
	var upperWorkNo = $("#form_upperWork").val();
	var docNo = $('#form_document').val();
	var fileNo = $('#form_file').val();
	
	var hasError = false;

	$("#has_errors").text("");

	if (workTitle == "") {
		$("#has_errors").append("Title이 비어있습니다");
		hasError = true;
	}
	if (id == "") {
		$("#has_errors").append("<br>담당자가 비어있습니다");
		hasError = true;
	}

	var validDate = /^20[0-1][0-9]-[0-1][0-9]-[0-3][0-9]$/; // 정규식
	if (startDate != "") {
		if (!startDate.match(validDate)) {
			$("#has_errors").append("<br>Date 형식이 맞지않습니다");
			hasErrors = true;
		}
	}
	if (deadDate != "") {
		if (!deadDate.match(validDate)) {
			$("#has_errors").append("<br>Date 형식이 맞지않습니다");
			hasErrors = true;
		}
	}
	var validNumber = /^[0-9]+$/;
	
	
	if(upperWorkNo != ""){
		if(!upperWorkNo.match(validNumber)){
			$("#has_errors").append("<br>상위일감 형식이 맞지않습니다.");
			hasErrors = true;
		}
	}else{
		upperWorkNo = 0;
	}
	
	if(docNo != ""){
		if(!docNo.match(validNumber)){
			$("#has_errors").append("<br>문서번호 형식이 맞지않습니다.");
			hasErrors = true;
		}
	}else{
		docNo = 0;
	}
	if(fileNo != ""){
		if(!fileNo.match(validNumber)){
			$("#has_errors").append("<br>파일번호 형식이 맞지않습니다.");
			hasErrors = true;
		}
	}else{
		fileNo = 0;
	}
	

	if (hasError == false) {

		$.ajax({
			url : "project/createWork/action",
			// type : "POST",
			data : ({
				workType : workType,
				workState : workState,
				workTitle : workTitle,
				workPriority : workPriority,
				workExplanation : workExplanation,
				id : id,
				startDate : startDate,
				file : file,
				coWorkers:coWorkers,
				workProgress:workProgress,
				deadDate:deadDate,
				upperWorkNo:upperWorkNo,
				docNo:docNo,
				fileNo:fileNo
			}),
			cache : false,
			contentType : "text/plain; charset=UTF-8",
			success : function(data) {
				if (data == "fail_id") {
					alert("id가 잘못입력되었습니다");
				} else if (data == "fail_id_project") {
					alert("이 project에 속한 id가 아닙니다");
				} else if (data == "fail_project") {
					alert("project 번호가 잘못되었습니다");
				} else if (data == "fail_title_blank") {
					alert("title이 비어있습니다");
				} else if (data == "success") {
					$("#complete").text("새로운 업무가 추가되었습니다");
				} else {
					alert("알수 없는 오류가 발생했습니다");
				}
			}
		});

	}

}

function get_schedule(year, month) {
	$('.board_contents').load('employee/schedule/changeMonth', {
		year : year,
		month : month
	});

}

function get_Memberschedule(year, month, empNo) {
	setEmpNo(empNo);
	$('.board_contents').load('teamMember/schedule/changeMonth', {
		year : year,
		month : month,
		empNo : getEmpNo()
	});

}

function get_calendar(year, month) {
	$('.project_contents').load('project/calendar/changeMonth', {
		year : year,
		month : month
	});

}

function pick_work(workNo) {
	setWorkNo(workNo);
	$.history.load("projectPickWork");
}
function pick_work2(workNo){
	setWorkNo(workNo);
	$('section#team_page').css({"background-color":"inherit","display":"none"});
	$.history.load("projectPickWork");
	
}
function work_list_with_num(pageNum){
	setWorkPageNum(pageNum);
	$.history.load("workListWithPageNum" + pageNum);
}

// project page function
function project_main(projectNo) {
	$.ajax({
		url : "project/projectMain/",
		// type: "POST",
		data : ({
			projectNo : projectNo
		}),
		cache : false,
		contentType : "text/plain; charset=UTF-8",
		success : function(data) {
			$.history.load("projectMainAction");
		}
	});
}
function project_summary() {
	$.history.load("projectSummary");
}
function project_jobhistory() {
	$.history.load("projectJobHistory");
}
function project_creatework() {
	$.history.load("projectCreateWork");
}
function work_page(workNo) {
	setWorkNo(workNo);
	$.history.load("projectWorkPage");
}
function project_gantt() {
	$.history.load("projectGantt");
}
function project_calendar() {
	$.history.load("projectCalendar");
}
function project_document() {
	$.history.load("projectDocument");
}
function project_file() {
	$.history.load("projectFile");
}
function project_worklist() {
	$.history.load("projectWorkList");
}
function project_work_modify(workNo) {
	setWorkNo(workNo);
	$.history.load("projectWorkModify");
}
///////////////////////////////////////////////////project printOut
function project_print_out(){
	$.history.load("projectPrintOut");
}


function employee_progress() {
	$('#status_content').load('employee/progress', function() {
		$('#work_content').hide().fadeIn();
	});
}
function employee_order() {
	$('#status_content').load('employee/order', function() {
		$('#work_content').hide().fadeIn();
	});
}

function employee_schedule() {
	$.history.load("employeeSchedule");
}

function board_list() {
	$.history.load("boardList");
}
function board_write() {
                                                                                     
	$.history.load("boardWrite");
}
function board_modify(empBoardNo) {
	setEmpBoardNo(empBoardNo);
	$.history.load("boardModify");
}

function board_comment_write(boardNo) {
	var commentContents = $('textarea#commentContents').val();
	$('textarea#commentContents').val('');

	$.ajax({
		url : "employee/comment/write",
		data : ({
			boardNo : boardNo,
			commentContents : commentContents
		}),
		cache : false,
		contentType : "text/plain; charset=UTF-8",
		success : function(data) {
			$('.board_contents').load('employee/contents/' + getEmpBoardNo(), {
				num : getPageNum(), updateComment:true
			});
		}
	});

}

function board_list_with_num(pageNum) {
	setPageNum(pageNum);
	$.history.load("boardListWithPageNum" + pageNum);
}
function board_list_page(pageNum) {

	// $('.board_contents').load('employee/list', {num:pageNum});
	setPageNum(pageNum);
	$.history.load("boardListPage");
}
function board_contents(empBoardNo, pageNum) {
	setEmpBoardNo(empBoardNo);
	setPageNum(pageNum);

	$.history.load("boardContents");
}




function teamMemberInfo(empNo){
	setEmpNo(empNo);
	$.history.load("teamMemberInfo" + empNo);
}
function teamMember_progress(empNo) {
	setEmpNo(empNo);
	$('#status_content').load('teamMember/progress',{empNo:getEmpNo()}, function() {
		$('#work_content').hide().fadeIn();
	});
}

function teamMember_order(empNo) {
	setEmpNo(empNo);
	$('#status_content').load('teamMember/order',{empNo:getEmpNo()}, function() {
		$('#work_content').hide().fadeIn();
	});
}
function teamMember_schedule(empNo) {
	setEmpNo(empNo);
	$.history.load("teamMemberSchedule");
}
function memberboard_write(empNo) {
	setEmpNo(empNo);

	$.history.load("memberboardWrite");
}
function memberboard_modify(empBoardNo, empNo, empBoardId, loginId) {
	if(compareObject(empBoardId, loginId)){
		setEmpBoardNo(empBoardNo);
		setEmpNo(empNo);
		$.history.load("memberboardModify");	
	}else{
		alert('수정할 권한이 없습니다.');
		return false;
	}
}

function memberboard_comment_write(boardNo, empNo) {
	setEmpNo(empNo);
	var commentContents = $('textarea#commentContents').val();
	$('textarea#commentContents').val('');

	$.ajax({
		url : "teamMember/comment/write",
		data : ({
			boardNo : boardNo,
			commentContents : commentContents,
			empNo : getEmpNo()
		}),
		cache : false,
		contentType : "text/plain; charset=UTF-8",
		success : function(data) {
			$('.board_contents').load('teamMember/contents/' + getEmpBoardNo(), {
				num : getPageNum(), updateComment:true, empNo:getEmpNo()
			});
		}
	});

}
function memberboard_contents(empBoardNo, pageNum, empNo) {
	setEmpBoardNo(empBoardNo);
	setPageNum(pageNum);
	setEmpNo(empNo);

	$.history.load("memberBoardContents");
}
function memberboard_list(empNo) {
	setEmpNo(empNo);
	$.history.load("memberboardList");
}
function memberboard_list_with_num(pageNum, empNo) {

	// $('.board_contents').load('employee/list', {num:pageNum});
	setEmpNo(empNo);
	setPageNum(pageNum);
	$.history.load("memberboardListWithPageNum" + pageNum);
}

function dept_board_list(){
	$.history.load("deptBoardList");
}
function dept_board_list_with_num(deptBoardPageNum){
	setDeptBoardPageNum(deptBoardPageNum);
	$.history.load("deptBoardListPageNum"+deptBoardPageNum);
}
function dept_board_list_page(deptBoardPageNum){
	setDeptBoardPageNum(deptBoardPageNum);
	$.history.load("deptBoardListPage");
}
function dept_board_contents(boardNo, deptBoardPageNum){
	setDeptBoardNo(boardNo);
	setDeptBoardPageNum(deptBoardPageNum);
	$.history.load("deptBoardContents");
}
function deptBoardWrite() {
	$.history.load("deptBoardWrite");
}
function deptBoardSubmit() {

	var title = $("input#title").val();
	var content = oEditors.getById["board_content"].getIR();
	if (isTitleAndArticleBlank(title, content)) {
		alert("빈칸이 있습니다.");
	} else {
		$.ajax({
			url : "dept/writeAction",
			type: "POST",
			cache : false,
			data : ({
				title : $("input#title").val(),
				article : oEditors.getById["board_content"].getIR()
			}),
			success : function(data) {
				alert("입력 성공하였습니다");
				dept_board_list();
			}
		
		});
	}

}
function dept_board_modify(deptBoardNo) {
	setDeptBoardNo(deptBoardNo);
	$.history.load("deptBoardModify"); 
}

function deptBoardContentModify(deptBoardNo) {

	var title = $("input#title").val();
	var content = oEditors.getById["board_content"].getIR();

	if (isTitleAndArticleBlank(title, content)) {
		alert("빈칸이 있습니다.");
	} else {
		$.ajax({
			url : "dept/modifyAction",
			// type: "POST",
			cache : false,
			data : ({
				title : title,
				article : content,
				deptBoardNo : deptBoardNo
			}),
			contentType : "text/plain; charset=UTF-8",
			success : function(data) {
				alert("수정 성공하였습니다");
				dept_board_list();
			}
		});
	}

}
function dept_board_delete(deptBoardNo) {
	if (confirm('정말 삭제하시겠습니까?')) {

		$.ajax({
			url : "dept/delete/ + " + deptBoardNo,
			// type: "POST",
			cache : false,
			contentType : "text/plain; charset=UTF-8",
			success : function(data) {
				alert('삭제되었습니다');
				dept_board_list();
			}
		});
	}
}
function dept_board_comment_write(boardNo) {
	var commentContents = $('textarea#commentContents').val();
	$('textarea#commentContents').val('');
	$.ajax({
		url : "dept/comment/write",
		data : ({
			boardNo : boardNo,
			commentContents : commentContents
		}),
		cache : false,
		contentType : "text/plain; charset=UTF-8",
		success : function(data) {
			$('.dept_board').load("dept/contents/"+getDeptBoardNo(), {
				num : getDeptBoardPageNum(), updateComment:true
			});
		}
	});
	
}


// contents.jsp******************
function board_delete(empBoardNo) {
	if (confirm('정말 삭제하시겠습니까?')) {

		$.ajax({
			url : "employee/delete/ + " + empBoardNo,
			// type: "POST",
			cache : false,
			contentType : "text/plain; charset=UTF-8",
			success : function(data) {
				alert('삭제되었습니다');
				board_list();
			}
		});
	}
}

function memberboard_delete(empBoardNo, empNo, empBoardId, loginId) {
	
	if (confirm('정말 삭제하시겠습니까?')) {
		if(compareObject(empBoardId, loginId)){
			setEmpNo(empNo);
			$.ajax({
				url : "teamMember/delete/ + " + empBoardNo,
				// type: "POST",
				cache : false,
				data : ({empNo : getEmpNo()}),
				contentType : "text/plain; charset=UTF-8",
				success : function(data) {
					alert('삭제되었습니다');
					memberboard_list(empNo);
				}
			});	
		}else{
			alert('삭제할 권한이 없습니다.');
			return false;
		}
	}else{
		return false;
	}
}

// writeBoard.jsp******************
function boardContentSubmit() {

	var title = $("input#title").val();
	var content = oEditors.getById["board_content"].getIR();
	if (isTitleAndArticleBlank(title, content)) {
		alert("빈칸이 있습니다.");
	} else {
		$.ajax({
			url : "employee/writeAction",
			type: "POST",
			data : {
				title : $("input#title").val(),
				article : oEditors.getById["board_content"].getIR()
			},
			success : function(data) {
				alert("입력 성공하였습니다");
				board_list();
			}
		
		});
	}

}

function memberBoardContentSubmit(empNo) {

	var title = $("input#title").val();
	var content = oEditors.getById["board_content"].getIR();
	setEmpNo(empNo);
	
	if (isTitleAndArticleBlank(title, content)) {
		alert("빈칸이 있습니다.");
	} else {
		$.ajax({
			url : "teamMember/writeAction",
			 type: "POST",
			cache : false,
			data : ({
				title : $("input#title").val(),
				article : oEditors.getById["board_content"].getIR(),
				empNo : getEmpNo()
			}),
			success : function(data) {
				alert("입력 성공하였습니다");
				memberboard_list(empNo);
			}
		});
	}

}

function document_submit() {
	var title = $("input#title").val();
	var content = oEditors.getById["board_content"].getIR();
	if (isTitleAndArticleBlank(title, content)) {
		alert("빈칸이 있습니다.");
	} else {
		$.ajax({
			url : "project/document/writeAction",
			 type: "POST",
			cache : false,
			data : ({
				docTitle : title,
				docContents : content
			}),
			success : function(data) {
				alert("입력 성공하였습니다");
				$('.project_contents').load('project/document');

			}
		});
	}
}

function boardContentModify(empBoardNo) {

	var title = $("input#title").val();
	var content = oEditors.getById["board_content"].getIR();

	if (isTitleAndArticleBlank(title, content)) {
		alert("빈칸이 있습니다.");
	} else {
		$.ajax({
			url : "employee/modifyAction",
			type: "POST",
			data : ({
				title : title,
				article : content,
				empBoardNo : empBoardNo
			}),
			success : function(data) {
				alert("수정 성공하였습니다");
				board_list();
			}
		});
	}

}

function memberboardContentModify(empBoardNo, empNo) {
	setEmpNo(empNo);
	var title = $("input#title").val();
	var content = oEditors.getById["board_content"].getIR();

	if (isTitleAndArticleBlank(title, content)) {
		alert("빈칸이 있습니다.");
	} else {
		$.ajax({
			url : "teamMember/modifyAction",
			// type: "POST",
			cache : false,
			data : ({
				title : title,
				article : content,
				empBoardNo : empBoardNo,
				empNo : getEmpNo()
			}),
			contentType : "text/plain; charset=UTF-8",
			success : function(data) {
				alert("수정 성공하였습니다");
				memberboard_list(empNo);
			}
		});
	}

}

function isTitleAndArticleBlank(title, content) {
	if (title.length == 0 || content.length == 5) {
		return true;
	}
	return false;
}

// myaccount page 관련
function employeeAccountToModifiePage() {
	$(".myaccount_contents").load("myaccount/modifiePages");
}
function modifiePageToMyAccountPage() {
	$(".myaccount_contents").load("myaccount/myAccountInfo");
}

function myAccountSubmit() {

	var deptNo = $("select#deptNo option:selected").val();
	var position = $("select#position option:selected").val();
	var teamNo = $("select#teamNo option:selected").val();
	var phone = $("input#phone").val();
	var email = $("input#email").val();
	var form = $("#accountform");

	$.ajax({
		url : "myaccount/modifieAction",
		// type: "POST",
		cache : false,
		data : ({
			deptNo : deptNo,
			position : position,
			teamNo : teamNo,
			phone : phone,
			email : email
		}),
		success : function(data) {
			form.submit();
			alert("입력 성공하였습니다");

		}
	});
}

// delete ProjectFile
function deleteProjectFile(fileNo, fileName) {
	if (confirm(fileNo + "번 " + fileName + "를 삭제 하시겠습니까?")) {
		$.ajax({
			url : "project/file/deleteprojectaction",
			// type: "POST",
			cache : false,
			data : ({
				fileNo : fileNo,
				fileName : fileName
			}),
			success : function(result) {
				projectFileList(result);
			}
		});
	}
}

function projectFileList(result) {
	$(".project_contents").load("project/file");
}

function compareObject(first, second){
	if(first==second){
		return true;
	}else{
		return false;
	}
}
// Department Team List
function moveTeamList(deptNo){
	$.ajax({
		url:"dept/deptMain/",
		data:({
			deptNo:deptNo
		}),
		cache: false,
		contentType : "text/plain; charset=UTF-8",
		success : function(data) {
			$.history.load("deptMainAction");
		}
	});
}
function moveBoardList(deptNo){
	$.history.load("deptBoardList");
}
function moveTeamsPage(deptNo, teamNo){
	setDeptNo(deptNo);
	setTeamNo(teamNo);
	$.history.load("deptTeamPage"+teamNo);
}

